//var Worker: new (scriptURL: string | URL, options?: WorkerOptions) => Worker

const workerUrl = import.meta.env.VITE_NODE_ENV === 'development' ? 'http://localhost:5173/works.js': '/works.js';
const work = new Worker(workerUrl, {
  type: "module", //可以使用import导入其他模块

}); //这里面只能传一个js文件，而且是同源文件

console.log('works----------');

work.onmessage = function (e) {
  console.log(e.data);
};
work.postMessage("hello");


// addEventListener和onmessage 都是用来接收消息的
work.addEventListener('message', function (e) {
  
})